package com.company.project.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.company.project.common.exception.BusinessException;
import org.apache.commons.lang.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import java.util.List;
import com.company.project.common.utils.DataResult;

import com.company.project.entity.AActiveTypeEntity;
import com.company.project.service.AActiveTypeService;

import javax.validation.Valid;


/**
 * ${comments}
 *
 * @author wenbin
 * @email *****@mail.com
 * @date 2022-06-06 09:36:56
 */
@Controller
@RequestMapping("/")
public class AActiveTypeController {
    @Autowired
    private AActiveTypeService aActiveTypeService;


    /**
    * 跳转到页面
    */
    @GetMapping("/index/aActiveType")
    public String aActiveType() {
        return "aactivetype/list";
        }

    @ApiOperation(value = "新增")
    @PostMapping("aActiveType/add")
    @RequiresPermissions("aActiveType:add")
    @ResponseBody
    public DataResult add(@RequestBody @Valid AActiveTypeEntity aActiveType){
        aActiveTypeService.save(aActiveType);
        return DataResult.success();
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("aActiveType/delete")
    @RequiresPermissions("aActiveType:delete")
    @ResponseBody
    public DataResult delete(@RequestBody @ApiParam(value = "id集合") List<String> ids){
        aActiveTypeService.removeByIds(ids);
        return DataResult.success();
    }

    @ApiOperation(value = "更新")
    @PutMapping("aActiveType/update")
    @RequiresPermissions("aActiveType:update")
    @ResponseBody
    public DataResult update(@RequestBody @Valid AActiveTypeEntity aActiveType){
        if(null==aActiveType.getId()){
            throw new BusinessException("活动类型ID不存在");
        }
        aActiveTypeService.updateById(aActiveType);
        return DataResult.success();
    }

    @ApiOperation(value = "查询分页数据")
    @PostMapping("aActiveType/listByPage")
    @RequiresPermissions("aActiveType:list")
    @ResponseBody
    public DataResult findListByPage(@RequestBody AActiveTypeEntity aActiveType){
        Page page = new Page(aActiveType.getPage(), aActiveType.getLimit());
        LambdaQueryWrapper<AActiveTypeEntity> queryWrapper = Wrappers.lambdaQuery();
        //查询条件示例
        queryWrapper.like(StringUtils.isNotBlank(aActiveType.getName()),AActiveTypeEntity::getName, aActiveType.getName());
        IPage<AActiveTypeEntity> iPage = aActiveTypeService.page(page, queryWrapper);
        return DataResult.success(iPage);
    }

}
